//
// MaFenetre.cpp for  in /home/goldbe_y//cpp/plazza-2014-bramar_g/Qt
//
// Made by yoni goldberg
// Login   <goldbe_y@epitech.net>
//
// Started on  Sun Apr 17 16:46:17 2011 yoni goldberg
// Last update Fri Apr 29 19:50:06 2011 yoni goldberg
//

#include "MaFenetre.hpp"
#include "convert.hpp"
#include "maths.hpp"

MaFenetre::MaFenetre(QApplication &app)
{
  setFixedSize(450,150);
  Bienvenue = new QLabel("205inter");
  layout = new QGridLayout;
  Centree = new QPushButton("Loi Normale Centree");
  Normal = new QPushButton("Loi Normale");
  min = new QLineEdit();
  max = new QLineEdit();
  mu = new QLineEdit();
  sigma = new QLineEdit();
  Quit = new QPushButton("Quitter");
  Place(app);
}

void		MaFenetre::Place(QApplication &app)
{
  layout->addWidget(Bienvenue, 0, 0, 1, 5, Qt::AlignHCenter);
  layout->addWidget(Centree, 1, 0, 1, 2, Qt::AlignHCenter);
  layout->addWidget(Normal, 1, 2, 1, 2, Qt::AlignHCenter);
  layout->addWidget(min, 2, 0);
  layout->addWidget(max, 2, 1);
  layout->addWidget(mu, 2, 2);
  layout->addWidget(sigma, 2, 3);
  layout->addWidget(Quit,3 ,4);
  QWidget::connect(Quit, SIGNAL(clicked()), &app, SLOT(quit()));
  QWidget::connect(Centree, SIGNAL(clicked()), this, SLOT(loi_centree()));
  QWidget::connect(Normal, SIGNAL(clicked()), this, SLOT(loi_normale()));
  setLayout(layout);
}

void		MaFenetre::loi_centree()
{
  if (!min->displayText().isEmpty() && !max->displayText().isEmpty())
    {
      std::string temp1,temp2;
      temp1 = min->displayText().toStdString();
      temp2 = max->displayText().toStdString();
      string_to_var(val_min, temp1);
      string_to_var(val_max, temp2);
      Maths	test(val_min, val_max);
      SDL_opt       win(700, 600, "205 Inter loi normale centree");
      test.loi();
      test.courbe(&win);
    }
  else
    {
      QMessageBox::critical(this, "Erreur", "Veuillez rentrer a et b");
    }
}

void		MaFenetre::loi_normale()
{
  if (!min->displayText().isEmpty() && !max->displayText().isEmpty() && !mu->displayText().isEmpty() && !sigma->displayText().isEmpty())
    {
      std::string temp1,temp2,temp3,temp4;
      temp1 = min->displayText().toStdString();
      temp2 = max->displayText().toStdString();
      temp3 = mu->displayText().toStdString();
      temp4 = sigma->displayText().toStdString();
      string_to_var(val_min, temp1);
      string_to_var(val_max, temp2);
      string_to_var(val_mu, temp3);
      string_to_var(val_sigma, temp4);
      if (val_sigma == 0)
	QMessageBox::critical(this, "Erreur", "Sigma >= 0");
      else
	{
	  Maths	test(val_min, val_max, val_mu, val_sigma);
	  SDL_opt       win(700, 600, "205 Inter loi normale");
	  test.loi();
	  test.courbe(&win);
	}
    }
  else
    {
      QMessageBox::critical(this, "Erreur", "Veuillez rentrer a, b, mu et sigma");
    }
}
